import {
	defineConfig
} from "vite"
import config from './config.js'
import uni from "@dcloudio/vite-plugin-uni"

//引入自动引入插件
import AutoImport from 'unplugin-auto-import/vite'
// const postcssPresetEnv = require("postcss-preset-env")
const path = require("path")

export default defineConfig({
	// resolve: {
	//   alias: {
	//     'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js'
	//   }
	// },
	plugins: [
		uni(),
		AutoImport({
			include: [
				/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
				/\.vue$/, /\.vue\?vue/, // .vue
				/\.md$/, // .md
			],
			imports: [
				'vue',
				'uni-app',
			],
			dts: 'src/auto-imports.d.ts',
		}),
	],

	css: {
		preprocessorOptions: {
			scss: {
				additionalData: `@import "@/common/styles/variables.scss";`,
			},
		},
	},

	server: {
		port: 9529,
		open: false,
		proxy: {
			"/api": {
				target: config.apiBaseUrl,
				changeOrigin: true,
				// pathRewrite: {
				//   '^/api': '/'
				// }
				rewrite: (path) => {
					return path.replace(/^\/api/, "/")
				},
			},
		},
	}
})